// 通用的 文件上传 组件
import React      from 'react';
import FileUpload from './react-fileupload.jsx';

class FileUploader extends React.Component{
  render(){
    /*set properties， res 就是后端返回的数据, chooseAndUpload 自动上传*/
    const options={
      baseUrl         :'/manage/product/upload.do',
      fileFieldName   : 'upload_file',
      datatype        : 'json',
      chooseAndUpload : true,
      uploadSuccess   : (res) => {
        this.props.onSuccess(res.data);
      },
      uploadError     : (err) => {
        this.props.onError(err.Msg || '上传图片出错拉');
      }
    }
    /*Use FileUpload with options*/
    /*Set two dom with ref*/
    return (
      <FileUpload options={options}>
        <button className="btn btn-xs btn-default" ref="chooseAndUpload">请选择图片</button>
      </FileUpload>
    )	        
  }
}

export default FileUploader;

